package com.xiangge.zuoye2;

import java.util.Scanner;

public class Demo8 {
    public static void main(String[] args) {
        int[] arr = {17, 29, 34, 42, 51};
        System.out.println("请输入一个数据：");
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();

        int count = 0;
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==x){
                index = i;
                count++;
            }
        }
        if (count>0){
            System.out.println("index = " + index);
        }else {
            System.out.println("-1");
        }
    }
}
